home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1679 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  997 b 

  1. Path: ecf2.puc.edu!bivey
  2. From: bivey@ecf2.puc.edu (Bruce Ivey)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Help, best way to compare doubles
  5. Date: 16 Jan 1996 05:43:17 GMT
  6. Organization: CRL Dialup Internet Access
  7. Message-ID: <4dfdtl$phv@nntp.crl.com>
  8. References: <4da169$mm4@mercury.IntNet.net>
  9. NNTP-Posting-Host: ecf2.puc.edu
  10.  
  11. Jeff Tomich (jtomich@IntNet.net) wrote:
  12. : Looking for a way to compare doubles for equality.
  13.  
  14. : thanks, Jeff
  15.  
  16. The first question to ask is "how equal"?  In general, one picks some
  17. error limit, such as  e = 1E-6;   then uses it in this form:
  18.  
  19.    if (fabs(n1 - n2) < e)  // then they are considered equal
  20.    else                    // they are considered different
  21.  
  22. -----------------------------------------------------------------------------
  23. Bruce Ivey         Dept of Physics & Computer Science   Pacific Union College
  24. Angwin, CA 94508            bivey@puc.edu                      (707) 965-7269
  25. =============================================================================
  26.